<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="作业名称" prop="logName">
                <el-input v-model="queryParams.logName" placeholder="请输入作业名称" clearable style="width: 240px"
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="结果码" prop="logCode">
                <el-input v-model="queryParams.logCode" placeholder="请输入结果码" clearable style="width: 240px"
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="调用方法" prop="logProc">
                <el-input v-model="queryParams.logProc" placeholder="请输入调用方法" clearable style="width: 240px"
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="创建时间" style="width: 420px">
                <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD HH:mm:ss" type="datetimerange"
                    range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" plain icon="Download" @click="handleExport"
                    v-hasPermi="['wms:log:export']">导出</el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="logList">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="id" align="center" prop="logId" width="80"/>
            <el-table-column label="作业名称" align="center" prop="logName" width="135" show-overflow-tooltip/>
            <el-table-column label="请求参数" align="center" prop="logParam" width="180" show-overflow-tooltip/>
            <el-table-column label="结果码" align="center" prop="logCode" show-overflow-tooltip/>
            <el-table-column label="结果信息" align="center" prop="logMsg" width="180" show-overflow-tooltip/>
            <el-table-column label="调用方法" align="center" prop="logProc" width="180" show-overflow-tooltip/>
            <el-table-column label="耗时(毫秒)" align="center" prop="costTime" />
            <el-table-column label="作业人员" align="center" prop="createName" />
            <el-table-column label="创建时间" align="center" prop="createDate" width="180">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script setup name="Log">
import { listLog, getLog } from "@/api/wms/log";

const { proxy } = getCurrentInstance();

const logList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);

const data = reactive({
    form: {},
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        logName: null,
        logParam: null,
        logCode: null,
        logMsg: null,
        logProc: null
    },
    rules: {
    }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询作业日志列表 */
function getList() {
    loading.value = true;
    listLog(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
        logList.value = response.rows;
        total.value = response.total;
        loading.value = false;
    });
}

// 表单重置
function reset() {
    form.value = {
        logId: null,
        logName: null,
        logParam: null,
        logCode: null,
        logMsg: null,
        logProc: null
    };
    proxy.resetForm("logRef");
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    dateRange.value = [];
    proxy.resetForm("queryRef");
    handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
    proxy.download('wms/log/export', {
        ...queryParams.value
    }, `log_${new Date().getTime()}.xlsx`)
}

getList();
</script>
